class RequestInfoTable

  def initialize(table)
    @cells = table.tds.to_a
  end

  def get_request_info
    {
        title: cell(0),
        status: cell(2),
        service: cell(3),
        request_type: cell(4),
        time_spent: cell(5),
        priority: cell(7),
        deadline: maybe_time_cell(8, 'None'),
        submitted_to: cell(10),
        submitted_by: cell(11),
        submitted_on: time_cell(12),
        assigned_to: cell(15),
        assigned_by: cell(16),
        assigned_on: time_cell(17),
        department_id: cell(19),
        closed_by: cell(20),
        closed_on: maybe_time_cell(21, 'None')
    }
  end

  private

  def maybe_time_cell(index, non_time_value)
    cell(index) { |s| s == non_time_value ? cell(index) : time_cell(index) }
  end

  def time_cell(index)
    cell(index) { |s| Time.parse s }
  end

  def cell(index)
    text = @cells[index].text
    block_given? ? yield(text) : text
  end

end